<template>
	<view class="view">

		<view class="bg-white" style="margin-top: 24rpx;padding: 24rpx 32rpx;">
		<!-- 上传文件的组件 -->	
			<yw-upfile-list v-model="pictureList" rootPath="fankui/files"></yw-upfile-list>
		</view>
		
		<button class="up-btn" @click="addPic">确认上传</button>  
	</view>
</template>

<script>
	export default {
		
		onLoad(e) {
			this.curData.studentId = e.studentId
		},
		data() {
			return {
				pictureList:[],
				curData:{
					studentId:null,
					pictureUrlList:[]
				},
				
			}
		},
		methods: {
			
		//确认上传
		addPic(){
			this.setFileList(this.pictureList)
			if(this.pictureList.length<=0){
				uni.showToast({
					title: '请选择图片',
					icon: 'error',    //
					duration: 1000    ,//持续时间为 2秒
					mask:true
				})
			}else{
				uni.$api.addStuPic(this.curData).then(data =>{
					
					uni.$common.toastSuccess("添加成功")
			
					uni.$emit('refreshData');
					uni.navigateBack({
						delta:1,
					})
					//跳转页面
					
				})
				
						
			
				}
			},

			setFileList(value) {
				this.curData.pictureUrlList = []
			
				if (typeof(value) == 'string') {
					if (uni.$common.isNotBlank(value)) {
						if (uni.$common.isHaveCharFromStr(value, ",")) {
							value.split(",").forEach(item => {
								this.curData.pictureUrlList.push(item)
							})
						} else {
							this.curData.pictureUrlList.push(value)
						}
					}
				} else if (typeof(value) == 'array') {
					value.forEach(item => {
						this.curData.pictureUrlList.push(item)
					})
				}
			},
			
		}
	}
</script>

<style>
	.view{
		background-color: #fff;
		position: fixed;
		top:0;
		left: 0%;
		width: 100%;
		height: 100%;
		object-fit: cover;
	}
	.bg-white{
		/* position: relative;
		left: 32%; */
	}
	.up-btn{
		background-color: #FDC722;
		color: #fff;
		width: 50%;
		border-radius: 40rpx;
		position: relative;
		top: 20%;
	}
</style>
